package utils

import "golang.org/x/crypto/bcrypt"

// GenerateFromPassword 使用bcrypt写入数据库时对密码加密
func GenerateFromPassword(password string) (string, error) {
	hash, err := bcrypt.GenerateFromPassword([]byte(password), bcrypt.MinCost)
	if err != nil {
		return "", err
	}
	return string(hash), nil
}

// CompareHashAndPassword 校验密码
func CompareHashAndPassword(hash, password string) error {
	err := bcrypt.CompareHashAndPassword([]byte(hash), []byte(password))
	return err
}
